package TestDemo;

class Dfs {
    private boolean[] st;
    private int count;
    private int[] arr;

    Dfs(int n) {
        st = new boolean[n + 1];
        arr = new int[n + 1];
    }

    public int dfs() {
        dfs(0);
        return count;
    }

    private void dfs(int u) {
        if (u == 5) {
            if ((arr[0] * 10 + arr[1]) * ((arr[2] * 10 + arr[3]) * 10 + arr[4]) == (arr[2] * 10 + arr[4]) * ((arr[0] * 10 + arr[3]) * 10 + arr[1])) {
                count++;
            }
            return;
        }

        for (int i = 1; i < st.length; i++) {
            if (!st[i]) {
                arr[u] = i;
                st[i] = true;
                dfs(u + 1);
                st[i] = false;
            }
        }
    }
}

public class TestDemo3 {
    public static void main(String[] args) {
        Dfs dfs = new Dfs(9);
        System.out.println("这样的算式有"+dfs.dfs()+"种");
    }
}
